
package Presentation;

import BLO.CauthuBLO;
import BLO.DoibongBLO;
import DAO.ResultsModel;
import DTO.CAUTHU;
import DTO.DOIBONG;
import DTO.Function;
import DTO.NGUOI;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class QuanlyCauthu extends javax.swing.JPanel {

   CauthuBLO ctBLO = new CauthuBLO();
   DoibongBLO dbBLO = new DoibongBLO();
    public QuanlyCauthu() {
        initComponents();
        
        try
        {
            ResultSet dtDB= dbBLO.Getdata1();
            while(dtDB.next())
            {
            cmbDoibong.addItem(dtDB.getString("Ten_DB"));
            }
              Function fn = new Function();
              String st = "";
              if(ctBLO.LayMaCuoi().trim().length()==0)
                  st="CT_00000";
              else
                 st = ctBLO.LayMaCuoi().trim();
             String str = fn.ID_Ketiep(st,"CT_");
             txtMact.setText(str);
            
            
            ResultsModel datatbCT = ctBLO.Getdata();
            JTable tb = new JTable(datatbCT);
            tb.setBounds(0, 0, 869, 300);
            JScrollPane jscoll = new JScrollPane(tb);
            jscoll.setBounds(0, 0, 869, 300);
            dgvCauthu.add(jscoll);
            
             SelectionListener listener = new SelectionListener(tb);
             tb.getSelectionModel().addListSelectionListener(listener);
             
        }catch (SQLException ex) {
            JOptionPane.showMessageDialog(this,ex.getMessage() );
        }
    }

      @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dgvCauthu = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtMact = new javax.swing.JTextField();
        txtTenct = new javax.swing.JTextField();
        cmbDoibong = new javax.swing.JComboBox();
        cmbVitri = new javax.swing.JComboBox();
        cmbQuoctich = new javax.swing.JComboBox();
        cmbSoao = new javax.swing.JComboBox();
        txtChieucao = new javax.swing.JTextField();
        txtCannang = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        dtpNamSinh = new com.toedter.calendar.JDateChooser();
        jPanel2 = new javax.swing.JPanel();
        btnDangky = new javax.swing.JButton();
        btnSua = new javax.swing.JButton();
        btnRefresh = new javax.swing.JButton();
        btnXoa = new javax.swing.JButton();
        btnTrove = new javax.swing.JButton();

        dgvCauthu.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout dgvCauthuLayout = new javax.swing.GroupLayout(dgvCauthu);
        dgvCauthu.setLayout(dgvCauthuLayout);
        dgvCauthuLayout.setHorizontalGroup(
            dgvCauthuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 837, Short.MAX_VALUE)
        );
        dgvCauthuLayout.setVerticalGroup(
            dgvCauthuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 216, Short.MAX_VALUE)
        );

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel11.setText("QUẢN LÝ CẦU THỦ");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel2.setText("Mã CT:");

        jLabel3.setText("Tên CT:");

        jLabel4.setText("Năm sinh:");

        jLabel5.setText("Số áo:");

        jLabel6.setText("Vị trí:");

        jLabel7.setText("Đội bóng:");

        jLabel9.setText("Cân nặng:");

        jLabel10.setText("Chiều cao:");

        jLabel8.setText("Quốc tịch:");

        cmbVitri.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tiền đạo", "Tiền vệ", "Hậu vệ", "Thủ môn" }));

        cmbQuoctich.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Việt Nam", "Lào", "Thái Lan", "Mỹ", "Brazil", "England" }));

        cmbSoao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99" }));

        jLabel21.setText("cm");

        jLabel22.setText("kg");

        dtpNamSinh.setDateFormatString("yyyy/dd/MM");
        dtpNamSinh.setIcon(null);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtMact, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTenct, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                    .addComponent(dtpNamSinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6))
                        .addGap(21, 21, 21))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbVitri, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbQuoctich, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel9)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cmbDoibong, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 101, Short.MAX_VALUE)
                        .addComponent(jLabel10)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmbSoao, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtCannang, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                            .addComponent(txtChieucao, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel22)
                            .addComponent(jLabel21))))
                .addGap(82, 82, 82))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(txtChieucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(txtCannang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addComponent(jLabel22))
                            .addComponent(jLabel21))
                        .addGap(18, 18, 18)
                        .addComponent(cmbSoao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(cmbDoibong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(cmbVitri, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbQuoctich, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(jLabel5)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtMact, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtTenct, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4)
                            .addComponent(dtpNamSinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel10))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnDangky.setText("Đăng ký");
        btnDangky.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDangkyActionPerformed(evt);
            }
        });

        btnSua.setText("Sửa");
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });

        btnRefresh.setText("Refresh");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        btnXoa.setText("Xóa");
        btnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaActionPerformed(evt);
            }
        });

        btnTrove.setText("Trở về");
        btnTrove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTroveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(btnDangky, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42)
                .addComponent(btnSua, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                .addComponent(btnXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addComponent(btnRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addComponent(btnTrove, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnDangky, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                    .addComponent(btnXoa, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnSua, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnRefresh, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnTrove, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(252, 252, 252)
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(281, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(18, Short.MAX_VALUE)
                .addComponent(dgvCauthu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 7, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 7, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(267, Short.MAX_VALUE)
                .addComponent(dgvCauthu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(47, 47, 47))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents
class SelectionListener implements ListSelectionListener {
   JTable table;
//Su kien selection change
    SelectionListener(JTable table) {
    this.table = table;}
    public void valueChanged(ListSelectionEvent e) {
          int row= table.getSelectedRow();
          if(row>=0)
          {
           txtMact.setText(table.getValueAt(row,0).toString().trim());
           cmbDoibong.setSelectedItem(table.getValueAt(row,1));
           txtTenct.setText(table.getValueAt(row,2).toString().trim());
           
           dtpNamSinh.setDateFormatString("MM/dd/yyyy");
           
           String n=table.getValueAt(row,3).toString();
           int nam=Integer.parseInt(n.substring(0,4));
         
           int thang=Integer.parseInt(n.substring(5,7));
           int ngay=Integer.parseInt(n.substring(8,10));
           
           Date d= new Date(nam-1900,thang,ngay);
           
        //   dtpNamSinh.setDate(d.getDay(table.getValueAt(row,3).toString()));
           
           dtpNamSinh.setDate(d);
           
           cmbQuoctich.setSelectedItem(table.getValueAt(row, 4));
           cmbVitri.setSelectedItem(table.getValueAt(row,5));
           cmbSoao.setSelectedItem(table.getValueAt(row,6));
           txtChieucao.setText(table.getValueAt(row,7).toString().trim());
           txtCannang.setText(table.getValueAt(row,8).toString().trim());
          }
    }
  }
    private void btnDangkyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDangkyActionPerformed
        // TODO add your handling code here:
       
        try
        {
        NGUOI nguoiDTO = new NGUOI();
        CAUTHU ctDTO = new CAUTHU();
        DOIBONG dbDTO = new DOIBONG();
        //set ma cau thu
        nguoiDTO.setManguoi(txtMact.getText().trim());
        nguoiDTO.setHoten(txtTenct.getText().trim());
        
        dtpNamSinh.setDateFormatString("MM/dd/yyyy");
        Calendar cal = dtpNamSinh.getCalendar();
        int datevar= cal.get(Calendar.DATE);
        int monthvar = cal.get(Calendar.MONTH);
        int yearvar = cal.get(Calendar.YEAR)-1900;
       
     
        Date d= new Date(yearvar, monthvar, datevar);
        nguoiDTO.setDate(d);
        nguoiDTO.setQuoctich(cmbQuoctich.getSelectedItem().toString());
        ctDTO.setNguoi(nguoiDTO);
        
        dbDTO.setTenDB(cmbDoibong.getSelectedItem().toString());
        dbDTO.setMaDB(dbBLO.GetMaFTenDoibong(dbDTO));
        ctDTO.setDoibong(dbDTO);
        
        
        ctDTO.setVitri(cmbVitri.getSelectedItem().toString());
        ctDTO.setSoao(Integer.parseInt(cmbSoao.getSelectedItem().toString()));
        ctDTO.setChieucao(Integer.parseInt(txtChieucao.getText().trim()));
        ctDTO.setCannang(Integer.parseInt(txtCannang.getText().trim()));
        
        ctBLO.InsertCT(ctDTO);
        ResultsModel datatbCT = ctBLO.Getdata();
        JTable tb = new JTable(datatbCT);
        tb.setBounds(0,0,869,300);
        JScrollPane js= new JScrollPane(tb);
        js.setBounds(0,0,869,300);
        dgvCauthu.removeAll();
        dgvCauthu.add(js);
        
         SelectionListener listener = new SelectionListener(tb);
         tb.getSelectionModel().addListSelectionListener(listener);
        }catch(Exception ex)
        {
            System.out.printf(ex.getMessage());
        }
        
        
        
    }//GEN-LAST:event_btnDangkyActionPerformed

    private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
        // TODO add your handling code here:
     try
        {
        NGUOI nguoiDTO = new NGUOI();
        CAUTHU ctDTO = new CAUTHU();
        DOIBONG dbDTO = new DOIBONG();
        //set ma cau thu
        nguoiDTO.setManguoi(txtMact.getText().trim());
        nguoiDTO.setHoten(txtTenct.getText().trim());
       
        dtpNamSinh.setDateFormatString("MM/dd/yyyy");
        Calendar cal = dtpNamSinh.getCalendar();
        int datevar= cal.get(Calendar.DATE);
        int monthvar = cal.get(Calendar.MONTH);
        int yearvar = cal.get(Calendar.YEAR)-1900;
        Date d= new Date(yearvar, monthvar, datevar);
        
        nguoiDTO.setDate(d);
        nguoiDTO.setQuoctich(cmbQuoctich.getSelectedItem().toString());
        ctDTO.setNguoi(nguoiDTO);
        
        dbDTO.setTenDB(cmbDoibong.getSelectedItem().toString());
        dbDTO.setMaDB(dbBLO.GetMaFTenDoibong(dbDTO));
        ctDTO.setDoibong(dbDTO);
                
        ctDTO.setVitri(cmbVitri.getSelectedItem().toString());
        ctDTO.setSoao(Integer.parseInt(cmbSoao.getSelectedItem().toString()));
        ctDTO.setChieucao(Integer.parseInt(txtChieucao.getText().trim()));
        ctDTO.setCannang(Integer.parseInt(txtCannang.getText().trim()));
        
        ctBLO.UpdateCT(ctDTO);
        ResultsModel datatbCT = ctBLO.Getdata();
        JTable tb = new JTable(datatbCT);
        tb.setBounds(0,0,869,300);
        JScrollPane js= new JScrollPane(tb);
        js.setBounds(0,0,869,300);
        dgvCauthu.removeAll();
        dgvCauthu.add(js);
        
         SelectionListener listener = new SelectionListener(tb);
         tb.getSelectionModel().addListSelectionListener(listener);
        }catch(Exception ex)
        {
            System.out.printf(ex.getMessage());
        }
    }//GEN-LAST:event_btnSuaActionPerformed

    private void btnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaActionPerformed
        // TODO add your handling code here:
        try
        {
        NGUOI nguoiDTO = new NGUOI();
        CAUTHU ctDTO = new CAUTHU();
        nguoiDTO.setManguoi(txtMact.getText().trim());
        ctDTO.setNguoi(nguoiDTO);
         //JOptionPane.showMessageDialog(null,ctDTO.getNguoi().getManguoi(),"Thong bao",JOptionPane.INFORMATION_MESSAGE);  
        ctBLO.DeleteCT(ctDTO);
        ResultsModel datatbCT = ctBLO.Getdata();
        JTable tb = new JTable(datatbCT);
        tb.setBounds(0,0,869,300);
        JScrollPane js= new JScrollPane(tb);
        js.setBounds(0,0,869,300);
        dgvCauthu.removeAll();
        dgvCauthu.add(js);
        
         SelectionListener listener = new SelectionListener(tb);
         tb.getSelectionModel().addListSelectionListener(listener);
        }catch(Exception ex)
        {
            System.out.printf(ex.getMessage());
        }
        
    }//GEN-LAST:event_btnXoaActionPerformed

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed

           Function fn = new Function();
              String st = "";
              if(ctBLO.LayMaCuoi().trim().length()==0)
                  st="CT_00000";
              else
                 st = ctBLO.LayMaCuoi().trim();
              String str = fn.ID_Ketiep(st,"CT_");

        txtMact.setText(str);
        txtTenct.setText("");
        txtChieucao.setText("");
        txtCannang.setText("");
        cmbDoibong.setSelectedIndex(0);
        cmbVitri.setSelectedIndex(0);
        cmbSoao.setSelectedIndex(0);
        cmbQuoctich.setSelectedIndex(0);
        
        // TODO add your handling code here:
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void btnTroveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTroveActionPerformed
   this.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_btnTroveActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDangky;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btnTrove;
    private javax.swing.JButton btnXoa;
    private javax.swing.JComboBox cmbDoibong;
    private javax.swing.JComboBox cmbQuoctich;
    private javax.swing.JComboBox cmbSoao;
    private javax.swing.JComboBox cmbVitri;
    private javax.swing.JPanel dgvCauthu;
    public com.toedter.calendar.JDateChooser dtpNamSinh;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField txtCannang;
    private javax.swing.JTextField txtChieucao;
    private javax.swing.JTextField txtMact;
    private javax.swing.JTextField txtTenct;
    // End of variables declaration//GEN-END:variables

    private void whlie(boolean next) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
